package widget;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import util.Utils;
import pojo.UserAccount;

public class UserInfoWidget extends ChessOnlineWidget{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2195323980192222009L;
	
	private Image mAvatar = null;
	private Image mBackground = null;
	private String mName;
	private String mScore;
	private String mHistory;
	private int posX;
	private int posY;

	public UserInfoWidget(UserAccount userAccount, int x, int y) {
		mName = userAccount.getName();
		mScore = String.valueOf(userAccount.getScore());
		mHistory = String.valueOf(userAccount.getWin()) +  "/" + String.valueOf(userAccount.getWin() + userAccount.getLose());
		
		this.posX = x;
		this.posY = y;
		
		// Create the icon
		try {
			mBackground = ImageIO.read(new File("Resources/Images/UserBox.png"));
			if(userAccount.getUsername().compareTo(Utils.getCurrentUser()) == 0) {
				mAvatar = ImageIO.read(new File("Resources/Images/Knight-icon.png"));
			}
			else {
				mAvatar = ImageIO.read(new File("Resources/Images/Knight-blue-icon.png"));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		g.drawImage(mBackground, posX, posY, null);
		g.drawImage(mAvatar, posX + 40, posY + 10, null);
		
		g.setFont(new Font("Buxton Sketch", Font.BOLD, 15));
		g.setColor(Color.ORANGE);
		g.drawString(mName, posX + 70, posY +107);
		g.drawString(mScore, posX + 70,posY + 127);
		g.drawString(mHistory, posX + 70, posY + 147);
	}
}
